# -*- coding: utf-8 -*-
import scrapy

from itemloader.items import JobboleArticalItem, ArticalItemLoader


class JobbleSpider(scrapy.Spider):
    name = 'jobble'
    allowed_domains = ['jobbole.com']
    start_urls = ['http://blog.jobbole.com/113691/']

    def parse(self, response):
        item_loader = ArticalItemLoader(item=JobboleArticalItem(), response=response)
        item_loader.add_css('title', '#post-113691 .entry-header h1::text')
        item_loader.add_css('time', '#post-113691 .entry-meta .entry-meta-hide-on-mobile::text')
        item_loader.add_css('content', '#post-113691 .entry')
        article_item = item_loader.load_item()
        yield article_item
        # item = JobboleArticalItem()
        # item['title'] = response.css('#post-113691 .entry-header h1::text').extract_first()
        # item['time'] = response.css('#post-113691 .entry-meta .entry-meta-hide-on-mobile::text').extract_first()
        # item['content'] = response.css('#post-113691 .entry p::text').extract_first()
        # yield item
